//
//  landingViewController.m
//  OurTourism
//
//  Created by dllo on 15/12/4.
//  Copyright © 2015年 Devil_Coming. All rights reserved.
//

#import "landingViewController.h"
#import "UserViewController.h"
#import "registeredViewController.h"
#import "Header.h"
#import <BmobSDK/Bmob.h>
@interface landingViewController ()
@property (weak, nonatomic) IBOutlet UITextField *account;
@property (weak, nonatomic) IBOutlet UITextField *password;
@property (nonatomic, strong) NSArray *tempArr;

@property (nonatomic, assign) BOOL judje;

@end

@implementation landingViewController



- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    
    
    
    
//        BmobObject *gameScore = [BmobObject objectWithClassName:@"Mzzzzz"];
//        [gameScore setObject:@"zzz" forKey:@"name"];
//        [gameScore setObject:@"123" forKey:@"score"];
//        [gameScore saveInBackgroundWithResultBlock:^(BOOL isSuccessful, NSError *error) {
//            //进行操作
//        }];
    
    
//    BmobQuery   *bquery = [BmobQuery queryWithClassName:@"Mzzzzz"];
//    
//    [bquery findObjectsInBackgroundWithBlock:^(NSArray *array, NSError *error) {
//        
//        //     NSMutableDictionary *dic = [NSMutableDictionary dictionary];
//        //        for (BmobObject *obj in array) {
//        //            //打印playerName
//        //            NSLog(@"obj.playerName = %@", [obj objectForKey:@"name"]);
//        //            //打印objectId,createdAt,updatedAt
//        //            NSLog(@"obj.objectId = %@", [obj objectId]);
//        //            NSLog(@"obj.createdAt = %@", [obj createdAt]);
//        //            NSLog(@"obj.updatedAt = %@", [obj updatedAt]);
//        //        }
//        for (int i= 0; i< array.count; i++) {
//            NSLog(@"%@",[array[i] objectForKey:@"name"]);
//        }
//        
//        
//        
//        NSLog(@"%@",[array[2] objectForKey:@"name"]);
//    }];
    

  
    self.judje = YES;
    
    
   
    
    
}
- (IBAction)landing:(id)sender {
    
    [self.navigationController popViewControllerAnimated:YES];
    
    
    BmobQuery   *bquery = [BmobQuery queryWithClassName:@"Mzzz"];
    
    [bquery findObjectsInBackgroundWithBlock:^(NSArray *array, NSError *error) {
        self.tempArr = array;
        NSLog(@"%ld  %@",self.tempArr.count, [array[0]  objectForKey:@"account"]);
        
        
        for (int i= 0; i < self.tempArr.count; i++) {
            if(self.account.text == [self.tempArr[i] objectForKey:@"account"])
            {
                NSLog(@"账号对");
                
                if(self.password.text == [self.tempArr[i] objectForKey:@"password"])
                {
                    NSLog(@"密码对");
                    
                [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"judge"];
                    
                }else
                {
                    NSLog(@"密码错");
                    [[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"judge"];
                }
                
            }else{
                NSLog(@"账号不存在");
                [[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"judge"];
            }
        }
        
    }];
   
  
    
    
}
- (IBAction)registered:(id)sender {
    registeredViewController *registered = [[registeredViewController alloc] init];

    [self.navigationController pushViewController:registered animated:YES];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
